home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / Text⁄Files / Voyeur 1.1.1 / Voyeur ƒ / MSG Shell ƒ / msg help.c < prev    next >
Text File  |  1994-02-26  |  4KB  |  205 lines

  1. /**********************************************************************\
  2.  
  3. File:        msg help.c
  4.  
  5. Purpose:    This module handles displaying the different help windows.
  6.  
  7.  
  8. Voyeur -- a no-frills file viewer
  9. Copyright ©1993-4, Mark Pilgrim
  10.  
  11. This program is free software; you can redistribute it and/or modify
  12. it under the terms of the GNU General Public License as published by
  13. the Free Software Foundation; either version 2 of the License, or
  14. (at your option) any later version.
  15.  
  16. This program is distributed in the hope that it will be useful,
  17. but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  19. GNU General Public License for more details.
  20.  
  21. You should have received a copy of the GNU General Public License
  22. along with this program in a file named "GNU General Public License".
  23. If not, write to the Free Software Foundation, 675 Mass Ave,
  24. Cambridge, MA 02139, USA.
  25.  
  26. \**********************************************************************/
  27.  
  28. #include "msg help.h"
  29. #include "msg graphics.h"
  30. #include "msg menus.h"
  31. #include "program globals.h"
  32. #include "Mercutio API.h"
  33.  
  34. int                gWhichHelp;
  35. Handle            gHelpIcon[4];
  36.  
  37. void InitHelp(void)
  38. {
  39.     int                i;
  40.     
  41.     for (i=0; i<4; i++)
  42.         gHelpIcon[i]=GetIcon(128+i);
  43. }
  44.  
  45. void DrawTheHelp(Boolean isColor)
  46. {
  47.     GrafPtr            curPort;
  48.     int                row;
  49.     Handle            textHandle;
  50.     Str255            theLine;
  51.     unsigned long    pos;
  52.     unsigned long    theSize;
  53.     unsigned char    theChar;
  54.     Rect            iconRect;
  55.     
  56.     GetPort(&curPort);
  57.     EraseRect(&(curPort->portRect));
  58.  
  59.     TextFont(geneva);
  60.     TextSize(9);
  61.     row=63;
  62.     textHandle=GetResource('TEXT', 399+gWhichHelp);
  63.     if (textHandle==0L)
  64.         return;
  65.     if (*textHandle==0L)
  66.         LoadResource(textHandle);
  67.     if (*textHandle==0L)
  68.         return;
  69.     pos=0L;
  70.     theSize=SizeResource(textHandle);
  71.     do
  72.     {
  73.         theLine[0]=0x00;
  74.         while ((pos<theSize) && ((theChar=*((unsigned char*)(((long)(*textHandle))+(pos++))))!=0x0d))
  75.         {
  76.             if (theChar=='^')
  77.                 AddNameToString(theLine, APPLICATION_NAME);
  78.             else
  79.             theLine[++theLine[0]]=theChar;
  80.         }
  81.         MoveTo(8, row);
  82.         DrawString(theLine);
  83.         row+=12;
  84.     }
  85.     while (pos<theSize);
  86.     ReleaseResource(textHandle);
  87.     
  88.     MoveTo(0, 46);
  89.     Line(300, 0);
  90.     
  91.     SetRect(&iconRect, 20, 7, 52, 39);
  92.     PlotIcon(&iconRect, gHelpIcon[0]);
  93.     OffsetRect(&iconRect, 228, 0);
  94.     PlotIcon(&iconRect, gHelpIcon[1]);
  95.     
  96.     GetItem(gHelpMenu, gWhichHelp, theLine);
  97.     TextFace(bold);
  98.     MoveTo(150-StringWidth(theLine)/2, 26);
  99.     DrawString(theLine);
  100.     TextFace(0);
  101. }
  102.  
  103. void AddNameToString(Str255 theLine, Str255 theStringToAdd)
  104. {
  105.     int            i;
  106.     
  107.     for (i=1; i<=theStringToAdd[0]; i++)
  108.         theLine[++theLine[0]]=theStringToAdd[i];
  109. }
  110.  
  111. void HelpEvent(void)
  112. {
  113.     Point        mouseLoc;
  114.     Rect        iconRect;
  115.     Boolean        isHilited;
  116.     
  117.     GetMouse(&mouseLoc);
  118.     SetRect(&iconRect, 20, 7, 52, 39);
  119.     if (PtInRect(mouseLoc, &iconRect))
  120.     {
  121.         isHilited=FALSE;
  122.         while (StillDown())
  123.         {
  124.             GetMouse(&mouseLoc);
  125.             if (PtInRect(mouseLoc, &iconRect))
  126.             {
  127.                 if (!isHilited)
  128.                     PlotIcon(&iconRect, gHelpIcon[2]);
  129.                 isHilited=TRUE;
  130.             }
  131.             else
  132.             {
  133.                 if (isHilited)
  134.                     PlotIcon(&iconRect, gHelpIcon[0]);
  135.                 isHilited=FALSE;
  136.             }
  137.         }
  138.         if (isHilited)
  139.         {
  140.             gWhichHelp--;
  141.             if (gWhichHelp==0)
  142.                 gWhichHelp=gNumHelp;
  143.             UpdateHelpWindow();
  144.         }
  145.     }
  146.     else
  147.     {
  148.         OffsetRect(&iconRect, 228, 0);
  149.         if (PtInRect(mouseLoc, &iconRect))
  150.         {
  151.             isHilited=FALSE;
  152.             while (StillDown())
  153.             {
  154.                 GetMouse(&mouseLoc);
  155.                 if (PtInRect(mouseLoc, &iconRect))
  156.                 {
  157.                     if (!isHilited)
  158.                         PlotIcon(&iconRect, gHelpIcon[3]);
  159.                     isHilited=TRUE;
  160.                 }
  161.                 else
  162.                 {
  163.                     if (isHilited)
  164.                         PlotIcon(&iconRect, gHelpIcon[1]);
  165.                     isHilited=FALSE;
  166.                 }
  167.             }
  168.             if (isHilited)
  169.             {
  170.                 gWhichHelp++;
  171.                 if (gWhichHelp>gNumHelp)
  172.                     gWhichHelp=1;
  173.                 UpdateHelpWindow();
  174.             }
  175.         }
  176.     }
  177. }
  178.  
  179. void HelpKeyEvent(char keyPressed)
  180. {
  181.     switch (keyPressed)
  182.     {
  183.         case 0x1c:
  184.             gWhichHelp--;
  185.             if (gWhichHelp==0)
  186.                 gWhichHelp=gNumHelp;
  187.             UpdateHelpWindow();
  188.             break;
  189.         case 0x1d:
  190.             gWhichHelp++;
  191.             if (gWhichHelp>gNumHelp)
  192.                 gWhichHelp=1;
  193.             UpdateHelpWindow();
  194.             break;
  195.     }
  196. }
  197.  
  198. void ShutDownHelp(void)
  199. {
  200.     int            i;
  201.     
  202. //    for (i=0; i<4; i++)
  203. //        ReleaseResource(gHelpIcon[i]);
  204. }
  205.